package com.gullmall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {

    /**
     * @return 所有对redisson的操作都是通过RedissonClient对象
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown") //表示bean销毁时会自动调用shutdown方法
    RedissonClient redisson() throws IOException {
        Config config = new Config();
        //单节点模式,如果redis有密码还要加上.setPassword()
        //redis://是固定的,也可以用"rediss://"来启用SSL连接
        config.useSingleServer().setAddress("redis://192.168.48.129:6379");
       /*集群模式.setAddress()变为
        config.useClusterServers()
                .addNodeAddress("127.0.0.1:7004", "127.0.0.2:7001"....);*/
       //创建RedissonClient实例到容器中
        return Redisson.create(config);
    }
}
